package fatcat.snowberry.diagram;

import java.awt.Font;

import fatcat.gui.snail.Component;
import fatcat.gui.snail.Container;
import fatcat.snowberry.gui.Bubble;
import fatcat.snowberry.gui.Label;

public class CommentBubble extends Bubble {
	
	private final Label label;
	private final Label title;

	public CommentBubble(Container owner, String title_text, String text) {
		super(owner);
		
		title = new Label(this);
		title.setAutoSize(true);
		title.setLocation(6, 6);
		title.setText(title_text);
		title.setFont(new Font("Dialog", Font.BOLD, 12));
		
		label = new Label(this);
		label.setAutoSize(true);
		label.setLocation(6, title.getBottom() + 2);
		setText(text);
	}
	
	@Override
	public int preferredHeight(Component c) {
		return label == null ? 0 : label.getBottom() + 6;
	}
	
	@Override
	public int preferredWidth(Component c) {
		return label == null ? 0 : (Math.max(title.getRight(), label.getRight()) + 6);
	}
	
	@Override
	public void setText(String text) {
		super.setText(text);
		if (label != null) {
			label.setText(text);
		}
	}

}
